package com.auctionhaus

class Customer {
	//C1
	String emailAddress
	String password
	String password2
	Date date

	static transients = ['password2']
	static hasMany = [bid:Bid, listings:Listing]

    static mappedBy = [listings:'seller', bid: 'buyer']
	static constraints = {     

	    // C-3
	    emailAddress(email:true, unique:true, blank:false)
	
	    // C-4
	    password(blank: false, nullable: false, size:6..8, validator: {password, obj ->
    	def password2 = obj.properties['password2']         
		if(password2 == null) return true 
		
		// skip matching password validation (only important when setting/resetting pass)         
		password2 == password ? true : ['invalid.matchingpasswords']     
		})

}

    static mapping = {
        cache: true
        //listings cache: 'read-only'
        listings updateable: false
    }


}
